<?php include_once('header.php'); ?>
<?php include_once('left_navigation.php'); ?>

<?php
	include_once('../classess/user_schedule.php');

	$user_sch = new user_sch();

	if(isset($_POST['select_schedule'])){
		$data = $user_sch->add_sch();
	}
?>
<style>
	.datepicker{
		z-index: 99999999999;
	}
</style>
<div class="col-lg-12"><!-- Start Middle Content Div-->
	<div class="box">
		<div class="box-header" data-original-title=""><!-- Start Box Header Div-->
			<h2><i class="fa fa-edit"></i><span class="break"></span>Trainer Info</h2>
			<div class="box-icon">
				<a href="gallery.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>
				<a href="gallery.html#" class="btn-close"><i class="fa fa-times"></i></a>
			</div>
		</div><!-- End Box Header Div-->
		<div class="box-content"><!-- Start Box Content Div-->
			<div class="row">
				<?php
					if(isset($_GET['tr_id'])){
						$select_single_trainer = "SELECT * FROM tbl_admin WHERE id = '".$_GET['tr_id']."'";								
						$course_trainer = mysql_query($select_single_trainer) or die(mysql_error());
						if(mysql_num_rows($course_trainer)){
						while($row_trainer = mysql_fetch_array($course_trainer)){
							$img_ext = $row_trainer['profile_image'];
							if($img_ext){
								$ext = explode(".",$img_ext);
								$extension = end($ext);
							}

				?>
				<div class="col-sm-4">
					<?php
						if($img_ext){
					?>
					<img src="<?php echo '../../admin/dashboard/profile_image/'.$row_trainer['id'].'.'.$extension;?>" class="product_image" alt="Product Image">
					<?php
						}else{
							echo 'No Profile Image';
						}
					?>
				</div><!--/col-->
				<div class="col-sm-8">
					
					<div id="img_description">
						<div class="desc_row">
							<div class="fl_left label_heading">Name : </div>
							<div class="fl_left label_description"><?php echo $row_trainer['Name']; ?></div>
							<div class="fl_clear"></div>
						</div>
						<div class="desc_row">
							<div class="fl_left label_heading">Email : </div>
							<div class="fl_left label_description"><?php echo $row_trainer['email']; ?></div>
							<div class="fl_clear"></div>
						</div>
						<div class="desc_row">
							<div class="fl_left label_heading">Skype Email :</div>
							<div class="fl_left label_description"><?php echo $row_trainer['skype_mail']; ?></div>
							<div class="fl_clear"></div>
						</div>
						<div class="desc_row">
							<div class="fl_left label_heading">Contact Number :</div>
							<div class="fl_left label_description"><?php echo $row_trainer['contact_number']; ?></div>
							<div class="fl_clear"></div>
						</div>
						<div class="desc_row">
							<div class="fl_left label_heading">Address :</div>
							<div class="fl_left label_description"><?php echo $row_trainer['Address']; ?></div>
							<div class="fl_clear"></div>
						</div>
						
						<div class="desc_row">
							<div class="fl_left label_heading">Schedule Time :</div>
							<div class="fl_left label_description">
								<?php
									$select_user_sch = "SELECT * FROM tbl_user_sel_sch_time WHERE trainer_id='".$row_trainer['id']."' AND trainee_id='".$_SESSION['id']."' AND course_id='".$row_trainer['course']."' AND date(sch_date)>=date(now()) ORDER BY id DESC LIMIT 1";

									$query_user_sch = mysql_query($select_user_sch) or die(mysql_error());
									if(mysql_num_rows($query_user_sch)>0){
										while($row_user_sch = mysql_fetch_array($query_user_sch)){
											$sel_slot = "SELECT * FROM tbl_timeslot WHERE id='".$row_user_sch['time_slot_id']."'";
											$query_slot = mysql_query($sel_slot) or die(mysql_error());
											if(mysql_num_rows($query_slot)>0){
												while($row_slot = mysql_fetch_array($query_slot)){
													echo 'Your Session Date is '.$row_user_sch['sch_date'].' At '.$row_slot['course_slot'];
												}
											}
										}										
									}else{
									
								?>
									<form method="POST"  action="<?php echo $_SERVER['PHP_SELF']; ?>?tr_id=1" name="add_user_schedule_form" id="add_user_schedule_form">
										<div id="sel_datepicker">
											<input type="text" class="form-control date-picker"  name="sel_date_schedule" id="date01" value="" data-date-format="yyyy-mm-dd"/ readonly style="width:40%; margin-bottom:5px;">
										</div>
										<div id="ajax_data" style="margin-top:15px;">
											<div id="domHtml"></div>
											<label style="text-align:right;">
												<input type="hidden" name="trainer_id" id="trainer_id" value="<?php echo $row_trainer['id']; ?>">
												<input type="hidden" name="course_id" id="course_id" value="<?php echo $row_trainer['course']; ?>">
												<input type="hidden" name="trainee_id" id="trainee_id" value="<?php echo $_SESSION['id']; ?>">
												<button type="button" class="btn btn-blue login_button" name="add_user_schedule" id="add_user_schedule" style="display:none;"><?php echo 'Add'; ?></button> 							
											</label>										
										</div>
									</form>
								<?php 
									}
								?>
							</div>
							<div class="fl_clear"></div>
						</div>

					</div>
					<?php 
								}
							}
						} ?>
				</div><!--/col-->
			</div><!-- End Row div -->
		</div><!-- End Box Content Div -->
	</div><!-- End Box Div-->
</div><!-- End Middle Content Div-->
<?php include_once('footer.php'); ?>
<script type="text/javascript" src="inner_js/bootstrap-datepicker.min.js"></script>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		$('.date-picker').datepicker();	

		$('#date01').datepicker({format: 'yyyy-mm-dd'}).on('changeDate', function(e){
			$(this).datepicker('hide');
			var date_val = $(this).val();
			var trnr_id = $('#trainer_id').val();
			var crs_id = $('#course_id').val();
			if($(this).val()!=''){
				$.ajax({
					url : '../classess/schedule.php',
					type : "POST",
					datatype:'json',
					data : {query:date_val,trainer_id:trnr_id,course_id:crs_id},
					success: function(j){
						var html ='';
						var data_js = $.parseJSON(j);	
						if(data_js){
							var data_length = data_js.length;
							
							for( var i=0;i<data_length;i++){							
								html +='<div style="float:left; width: 40%;"><div style="float:left; width: 20%;"><input type="checkbox" name="select_schedule[]" id="select_schedule" value="'+data_js[i]['time_slot_id']+'"></div><div style="float:left; width:80%; font-weight:normal;">'+data_js[i]['course_slot']+'</div><div style="clear:both;"></div></div>';
							}
							$('#add_user_schedule').css('display','block');
							$('#ajax_data #domHtml').html(html);
						}else{
							html += 'No Schedule';
							$('#add_user_schedule').css('display','none');
							$('#ajax_data #domHtml').html(html);
						}
						
					},
					error: function(j) {
						alert('failed'); 
					}	
				});
			}
		});

		$('#add_user_schedule').click(function(){
			if($('#select_schedule:checked').length == '0'){
				alert('Please Select atleast one time');
			}else{
				document.add_user_schedule_form.submit();
			}
		});

		$('.close').click(function(){
			$('.alert-info').addClass('hide');
		});
	});
</script>